#!/bin/bash
if [ ! -f ~/.ssh/id_rsa ];then
 ssh-keygen -t rsa
else
 echo "id_rsa has created ..."
fi

user="root" # login user name
passwd=""   # password for user

ip_list="200 201 202 203 204 205 206 207 208 209"

yum install expect -y

for ip_code in $ip_list
  do
    chmod 750 /root
    chmod -R 700 /root/.ssh
    ip="192.168.1."$ip_code
    echo $ip
    expect <<EOF
        set timeout 10
        spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $user@$ip
        expect {
        "yes/no" { send "yes\n";exp_continue }
        "password" { send "$passwd\n" }
        }
        expect "password" { send "$passwd\n" }
EOF
    done